package cn.lili.timetask.handler.impl.order;

import cn.hutool.core.util.StrUtil;
import cn.lili.cache.impl.RedisCache;
import cn.lili.modules.constant.CommonConstant;
import cn.lili.modules.order.order.client.OrderClient;
import cn.lili.timetask.handler.EveryHourExecute;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Component
@RequiredArgsConstructor
public class CityDistributionComissTaskExecute implements EveryHourExecute {


    private final OrderClient orderClient;
    @Resource
    private RedisCache redisCache;

    /**
     * 每日00点给城主发放收益
     */
    @Override
    public void execute() {
        Integer citydis_comiss_task_time = 1;
        String citydis_comiss_task_timeStr = redisCache.getString(CommonConstant.CITYDIS_COMISS_TASK_TIME);
        //执行时间
        if (StrUtil.isNotBlank(citydis_comiss_task_timeStr)) {
            citydis_comiss_task_time = Integer.valueOf(citydis_comiss_task_timeStr);
        }
        // 每日00点执行
        if (LocalDateTime.now().getHour() == citydis_comiss_task_time) {
            orderClient.executeCityDistributionComissLastMonthOrder();
        }
    }
}
